package operation;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOPeration{

    public void work(BookList bookList){
        System.out.println("删除图书!");
        System.out.println("请输入要查找的书的书名");
        Scanner in = new Scanner(System.in);
        String obj = in.nextLine();
        int index = bookList.getUsedSize();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(bookList.getPos(i).getName().equals(obj)){
                System.out.println("找到了，信息如下："+bookList.getPos(i));
                index = i;
                break;
            }
        }
        if(index < bookList.getUsedSize()){
            for (int i = index; i < bookList.getUsedSize()-1; i++) {
                bookList.setBooks(i,bookList.getPos(i+1));
            }
            bookList.setUsedSize(bookList.getUsedSize()-1);
            System.out.println("删除成功");
        }else{
            System.out.println("要删除的图书不存在");
        }
    }
}
